package com.tanhua.management.controller;

import com.tanhua.management.service.CommentService;
import com.tanhua.management.vo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("manage")
@Slf4j
/**
 *  评论列表翻页
 */
public class CommentManagerController {

    @Autowired
    private CommentService commentService;

    /**
     *  评论管理
     *      评论列表翻页
     * @param page  页尺寸
     * @param pageSize 页数
     * @param sortProp 排序字段
     * @param sortOrder ascending 升序 descending 降序
     * @param messageID 用户ID
     * @param token  铭牌
     * @return
     */
    @GetMapping("messages/comments")
    public ResponseEntity<PageResult> queryComment(
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "sortProp", defaultValue = "created") String sortProp,
            @RequestParam(value = "sortOrder", defaultValue = "descending") String sortOrder,
            @RequestParam(value = "messageID") String messageID
            , @RequestHeader("Authorization") String token) {
        try {
            PageResult pageResult = this.commentService.queryCommentList(pageSize, page, sortProp, sortOrder,messageID);
            if (null != pageResult) {
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("查询评论列表出错~  E = " + e);

        }
        return ResponseEntity.status(500).body(null);
    }


}

